/**
 * Created by 121 on 2016/4/08.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'highCharts'
], function ($, common, ready, template, Collection, Model, dialog, calendar, highCharts) {
    var id = getUrlPath(4);
    $('#parent-id').html(id);
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            this.event();
        },
        event: function () {
            $('#one-day').addClass('active');
            var _this = this;
            var oneday = function (e) {
                $.ajax({
                    url: _global.url.api + 'card/detail/' + id,
                    type: 'get',
                    success: function (res) {
                        var data = res.data[0];
                        console.log(data);
                        $('#card-detail-one-day').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: data.stat_date + '日24小时卡片' + data.card_title + '的数据明细'
                            },
                            xAxis: {
                                categories: data.categories,
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            },
                            yAxis: {
                                title: {
                                    text: '次数'
                                }
                            },
                            tooltip: {
                                //valueSuffix: ''
                                shared:true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: [{
                                name: '曝光次数',
                                data: data.show_hourly,
                                type: 'spline',
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '点击次数',
                                type: 'spline',
                                data: data.click_hourly,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '成交次数',
                                type: 'spline',
                                data: data.order_hourly,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }]
                        });
                    }
                });
            }
            oneday();

            $('#one-day').click(function (e) {
                $(e.target).siblings().removeClass('active');
                oneday();
                $('.card-detail-fourteen-day').hide();
                $('.card-detail-three-day').hide();
                $('.card-detail-one-day').show();
            })
            $('#fourteen-days').click(function (e) {
                $.ajax({
                    url: _global.url.api + 'card/detail/fourteen/' + id,
                    type: 'get',
                    success: function (res) {
                        //console.log(res.data);
                        $('#card-detail-fourteen-day').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: '过去14天的卡片数据明细'
                            },
                            xAxis: {
                                categories: res.data.stat_date,
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            },
                            yAxis: {
                                title: {
                                    text: '次数'
                                }
                            },
                            tooltip: {
                                shared:true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: [{
                                name: '曝光次数',
                                data: res.data.show_count,
                                type: 'spline',
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '点击次数',
                                type: 'spline',
                                data: res.data.click_count,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '成交次数',
                                type: 'spline',
                                data: res.data.order_count,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }]
                        });
                    }
                });
                $('.card-detail-fourteen-day').show();
                $('.card-detail-three-day').hide();
                $('.card-detail-one-day').hide();
                $(this).siblings().removeClass('active');
            })

            $('#three-days').click(function (e) {
                e.preventDefault();
                $.ajax({
                    url: _global.url.api + 'card/detail/three/' + id,
                    type: 'get',
                    success: function (res) {
                        console.log(res);
                        $('#card-detail-three-day').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: '过去3天的卡片数据明细'
                            },
                            xAxis: {
                                tickInterval: 4,
                                showFirstLabel: false,
                                categories: res.data.stat_date,
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '8px'
                                    }
                                }
                            },
                            yAxis: {
                                title: {
                                    text: '次数'
                                }
                            },
                            tooltip: {
                                shared:true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: [{
                                name: '曝光次数',
                                data: res.data.show_hourly,
                                type: 'spline',
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '点击次数',
                                type: 'spline',
                                data: res.data.click_hourly,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }, {
                                name: '成交次数',
                                type: 'spline',
                                data: res.data.order_hourly,
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }]
                        });
                    }
                });
                $('.card-detail-three-day').show();
                $('.card-detail-fourteen-day').hide();
                $('.card-detail-one-day').hide();
                $(this).siblings().removeClass('active');
            })
        }
    };
    new index();

});